﻿using System.IO;
using System.Web.Hosting;
using System.Security.Cryptography;
using System.Text;
using System.Web.Configuration;
using System.Data;
using System;
using System.Collections.Generic;

/// <summary>
/// StaticMethod 的摘要说明
/// </summary>
public class CommonHelper
{
    /// <summary>
    /// 弹出消息并跳转页面
    /// </summary>
    /// <param name="msg">消息内容</param>
    /// <param name="redirectUrl">跳转的url</param>
    /// <returns></returns>
    public static string alertMsgAndRedirect(string msg, string redirectUrl)
    {
        return "<script>alert('" + msg + "');window.location.href='" + redirectUrl + "'</script>";
    }

    /// <summary>
    /// 弹出消息
    /// </summary>
    /// <param name="msg">消息内容</param>
    /// <returns></returns>
    public static string alertMsg(string msg)
    {
        return "<script>alert('" + msg + "');</script>";
    }

    /// <summary>  
    /// 根据GUID获取16位的唯一字符串  
    /// </summary>  
    /// <param name=\"guid\"></param>  
    /// <returns></returns>  
    public static string GuidTo16String()
    {
        long i = 1;
        foreach (byte b in Guid.NewGuid().ToByteArray())
            i *= ((int)b + 1);
        return string.Format("{0:x}", i - DateTime.Now.Ticks).ToUpper();
    }
    /// <summary>  
    /// 根据GUID获取19位的唯一数字序列  
    /// </summary>  
    /// <returns></returns>  
    public static long GuidToLongID()
    {
        byte[] buffer = Guid.NewGuid().ToByteArray();
        return BitConverter.ToInt64(buffer, 0);
    }

    public static DateTime timestampToDateTime(double timestamp)
    {
        DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(timestamp);

        return dateTime;
    }
}